package com.jcw.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jcw.common.R;
import com.jcw.dto.DishDto;
import com.jcw.service.DishService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/dish")
public class DishController {

    @Resource
    private DishService dishService;

    @GetMapping("/page")
    public R<Page> pageR(@RequestParam int page,int pageSize,String name){
        return dishService.pagination(page,pageSize,name);
    }


    @PostMapping
    public R<String> addDish(@RequestBody DishDto dishDto){
        return dishService.addDish(dishDto);
    }

    @GetMapping("/{id}")
    public R<DishDto> echoDish(@PathVariable Long id){
        return dishService.echoDish(id);
    }

    @PutMapping
    public R<String> editDish(@RequestBody DishDto dishDto){
        return dishService.editDish(dishDto);
    }

    @PostMapping("/status/{statusCode}")
    public R<String> editStatus(@PathVariable int statusCode, String ids){
        return dishService.editStatus(statusCode,ids);
    }

    @DeleteMapping
    public R<String> delete(String ids){
        return dishService.delete(ids);
    }

    @GetMapping("/list")
    public R<List> listR(Long categoryId,Integer status){
        return dishService.dishList(categoryId,status);
    }


}
